/**
  ******************************************************************************
  * File Name          : main.h
  * Description        : This file contains the common defines of the application
  ******************************************************************************
  *
  * COPYRIGHT(c) 2017 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#include "stm32f0xx.h"
#include <stdio.h>
#include <assert.h>

#define CHPRINTF_USE_FLOAT TRUE

#ifndef bool
typedef enum {FALSE = 0, TRUE = !FALSE} bool;
#endif

#ifdef DEBUG
extern int mprintf(const char *format, ...);
extern bool _isDebugOn;
#   define debug(fmt, ...) if(_isDebugOn) mprintf(fmt, ##__VA_ARGS__)
#   define ON_DEBUG(foo) foo
#   define ON_RELEASE(foo)
#else
#   define debug(...)
#   define ON_DEBUG(foo)
#   define ON_RELEASE(foo) foo
#endif


#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#define BIT_SET(reg, bit) (reg) |= (bit)
#define BIT_CLR(reg, bit) (reg) &= ~ (bit)
#define BITS_SET(reg, mask, bits) do{reg = (reg & (~(mask))) | (bits);}while(0)
#define BIT_MASK(n) (0x01 << (n))

#define CALL_BACK(func, ...) do{\
    if(func != NULL)\
    {\
        func(__VA_ARGS__);\
    }\
}while(0)

typedef struct
{
    GPIO_TypeDef *port;
    uint16_t pin;
}Io_t;

#define _io(p, n) GPIO##p, GPIO_Pin_##n
#define IO(p, n) _io(p, n)
#define _IO_PORT(p, n) p
#define _IO_PIN(p, n)  n
#define IO_PORT(p, n) _IO_PORT(p, n)
#define IO_PIN(p, n)  _IO_PIN(p, n)


/**
  * @}
  */ 

/**
  * @}
*/ 

#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
